package com.techstar.ats.codec.live.decoder;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.codec.Decoder;
import com.techstar.ats.codec.StringCodec;
import com.techstar.ats.dxp.live.DeviceStatus;

public enum DeviceStatusDecoder implements Decoder<DeviceStatus> {
	INSTANCE;

	public DeviceStatus create() {
		return new DeviceStatus();
	}

	public void decode(ByteBuf buf, DeviceStatus value) {
		value.name = new StringCodec(24).get(buf);
		value.status = buf.readInt();
		int spare = buf.readInt();
		switch(value.type) {
			case PLATFORM:
				value.nextTime = spare >> 16 & 0xffff;
				value.nextLevel = spare >> 8 & 0xff;
				break;
			case SWITCH:
				value.limit = spare & 0xff;
		}
	}
}
